/**
 * 微信分享工具类，依赖于jquery或者zepto,也必须导入微信的sdk
 * sdk:http://res.wx.qq.com/open/js/jweixin-1.0.0.js
 * usage:
 * var tokenUrl = "/weichatToken";
 * var shareUrl = location.href.split('#')[0];//本页
 * var shareData = {
 *      title:'艺点点邀您体验',
 *      desc:'艺点点艺术培训管理系统‘,
 *      link: window.location.href,
 *      imgUrl: "http://test.yddkt.com/yddh5/images/a_img.png",
 *      trigger: function (res) {
 *      },
 *      success: function (res) {
 *          //分享成功回调
 *      },
 *      cancel: function (res) {
 *          //分享取消回调
 *      },
 *      fail: function (res) {
 *          //分享失败回调
 *      }
 *
 * }
 * WShare.share(tokenUrl, shareUrl, shareData);
 */
var WShare = {};
/**
 * 微信分享
 * @param tokenUrl
 *          获取分享的token
 * @param shareUrl
 *          需要分享的链接
 * @param shareData
 *          需要分享的数据
 */
WShare.share = function(tokenUrl, shareUrl, shareData){
    $.ajax({
        url: tokenUrl,
        type: "post",
        dataType: "json",
        async: false,
        data: {
            url: shareUrl,
        },
        success: function (result) {
            wx.config({
                debug: false,
                appId: result.appId,
                timestamp: result.timestamp,
                nonceStr: result.nonceStr,
                signature: result.signature,
                jsApiList: [
                    'checkJsApi',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo'
                ]
            });
        },
        error: function () {
            alert("分享配置错误");
        }
    });
    wx.ready(function () {
        wx.onMenuShareAppMessage(shareData);
        wx.onMenuShareTimeline(shareData);
        wx.onMenuShareQQ(shareData);
        wx.onMenuShareWeibo(shareData);
        wx.onMenuShareQZone(shareData);
    });
}
